import {Component, OnInit, Input, OnChanges, SimpleChanges} from '@angular/core';
import {PowerColModel} from '../../../models/kdm-response-model'
import {GetRTDataByKKSCodesService} from '../../../services/get-rtdata-by-kkscodes.service'
import {isUndefined} from "util";

@Component({
  selector: 'app-regional-unit-group',
  templateUrl: './regional-unit-group.component.html',
  styleUrls: ['./regional-unit-group.component.css']
})
export class RegionalUnitGroupComponent implements OnInit ,OnChanges  {
  ngOnChanges(changes: SimpleChanges): void {
    if(changes['startTime'] || changes['endTime']){
      if(this.groupID)
        this.id=this.groupID;
      // console.log(changes['staticTime'])
      this.initData()
    }
  }



  items: any

  @Input() public id:any;
  @Input() public groupID:number
  // @Input() public date:string
  @Input() public staticTime:number
  @Input() public startTime:string
  @Input() public endTime: string

  public rout:string

  constructor(
    private getAreaUnit:GetRTDataByKKSCodesService
  ) { }

  ngOnInit() {
    // this.staticTime=2
    if(this.groupID){
      this.id=this.groupID;
      this.rout='/pages/performance-analysis/regional-overview';
    }
    else {
      this.rout='/pages/performance-analysis/station-overview'
    }
    // if(typeof this.staticTime)
    //   this.initData()
  }


  public itemName:any[];
  public ymax:any
  public colDatas:PowerColModel[]
  cap_en: any;

  public initData() {
    this.getAreaUnit.getAreaUnit(this.id,this.staticTime)
      .subscribe(
        data=>{
          this.colDatas=data;
          // console.log(data)
          let capacity=[],energy=[];
          let max=0;
          this.itemName=[]
          this.colDatas.forEach(elem=>{
            if(elem.id!==2){
              this.itemName.push(elem.name)
              capacity.push(elem.capacity/10000);
              energy.push(elem.energy/10000);
            }
          });
          this.ymax=max;
          this.cap_en=[
            { name: '发电量', data:energy, color: 'rgba(186,60,61,1)', pointPadding: 0.1,},
            { name: '装机容量', data:capacity,color: 'rgba(248,161,63,.9)' ,pointPadding: 0.05, yAxis: 1}
          ];
        }
      )
  }
}



